package com.jetpackmvp.module

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.jetpackmvp.base.BasePresenter
import com.jetpackmvp.utils.LogUtil
import com.jetpackmvp.utils.RxHelper
import okhttp3.RequestBody

/**
 * @author: GY.LEE
 * @date: 2019-06-06
 * @Des:
 */
class UserPresenterImpl : BasePresenter<UserContract.View>(),
    UserContract.Presenter {

    private val userLiveData = MutableLiveData<String>()

    override fun getUser(params: RequestBody): LiveData<String> {

        val disposable = service.doLogin(params).compose(RxHelper.ioMain())
            .subscribe({ userLiveData.postValue(it.name) }, {
                mRootView?.showUserFailed()
            })


        LogUtil.e(mRootView.toString())
//        Thread.sleep(500)

        mRootView?.showUserSuccess()
//        mRootView?.dismissProgressDialog()

        addSubscription(disposable)
        return userLiveData

    }
}